//
//  TMPoiResultCell.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/23.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMPoiResultCell.h"
#import "TMRecommendModel.h"
#import "TMRecommendViewCell.h"
@interface TMPoiResultCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, assign) CGSize itemSize;
@end
@implementation TMPoiResultCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.listCollection registerNib:[UINib nibWithNibName:@"TMRecommendViewCell" bundle:nil] forCellWithReuseIdentifier:@"TMRecommendViewCell"];

}

//- (void)setModel:(TMRecommendModel *)model{
//    _model = model;
//}
-(void)setIsRecommend:(BOOL)isRecommend{
    _isRecommend = isRecommend;
}
- (void)setModelArray:(NSMutableArray *)modelArray{
    _modelArray = modelArray;
    [self.listCollection reloadData];
}
-(void)setListCollection:(UICollectionView *)listCollection{
    _listCollection = listCollection;
    _listCollection.delegate = self;
    _listCollection.dataSource = self;
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 8.;
    flowLayout.minimumInteritemSpacing = 0.;
    if (self.isRecommend == YES) {
         _itemSize = CGSizeMake(114 * kWindowW /375, 135 * kWindowW /375);
    }else{
         _itemSize = CGSizeMake(114 * kWindowW /375, 123 * kWindowW /375);
    }
    _listCollection.collectionViewLayout = flowLayout;
    [_listCollection registerNib:[UINib nibWithNibName:@"TMCourseSaleCell" bundle:nil] forCellWithReuseIdentifier:@"TMCourseSaleCell"];
    _listCollection.pagingEnabled = YES;
}

#pragma delegate datas

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return self.itemSize;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 12, 0, 12);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.modelArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TMRecommendViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TMRecommendViewCell" forIndexPath:indexPath];
    if (self.isRecommend == YES) {
        cell.model = self.modelArray[indexPath.row];
    }else{
        cell.localModel = self.modelArray[indexPath.row];
    }
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
        TMRecommendModel *model = self.modelArray[indexPath.row];
    if (self.block) {
        self.block(self.isRecommend, model.cid);
    }
}

@end
